<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">
    
    <xsl:key name="inputCurrencyID" match="report/exchanges/exchange/input_currency" use="."/>
    <xsl:key name="outputCurrencyID" match="report/exchanges/exchange/output_currency" use="."/>

<xsl:template match="/report">

 <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

 <fo:layout-master-set>
   <fo:simple-page-master master-name="intro" 
   font-family="Century Gothic, Geneva, sans-serif" 
   page-width="210mm" page-height="297mm" 
   margin-top="4cm" margin-bottom="1cm"
   margin-left="1cm" margin-right="1cm">
   <fo:region-body margin="3cm"/>
 </fo:simple-page-master>
 <fo:simple-page-master master-name="report" 
   font-family="Century Gothic, Geneva, sans-serif"
   font-size="11px"
   page-width="210mm" page-height="297mm"
   margin-left="15mm" margin-right="15mm">
   <fo:region-body margin-top="2cm" margin-bottom="2cm"/>
 </fo:simple-page-master>
 <fo:simple-page-master master-name="stats" 
   font-family="Century Gothic, Geneva, sans-serif"
   font-size="11px"
   page-width="210mm" page-height="297mm"
   margin-left="20mm" margin-right="20mm">
   <fo:region-body margin-top="25mm" margin-bottom="25mm"/>
 </fo:simple-page-master>
</fo:layout-master-set>
 
 

<fo:page-sequence master-reference="intro">
	<fo:flow flow-name="xsl-region-body">
		<fo:block text-align="center" font-weight="bold" font-size="22px" margin-bottom="80px" margin-top="80px" >
			MODERN CONTENT MANAGEMENT TECHNOLOGIES
		</fo:block>
		<fo:block  margin-left="2cm" font-weight="bold" font-size="14px" margin-bottom="2px" >
	        Authors:
	    </fo:block>
	    <xsl:for-each select="info/authors/author">
	    	<fo:block  margin-left="2cm" font-size="13px" >	        
	        	<xsl:value-of select="name" /> - 
	            <xsl:value-of select="index_number" /> - 
	            <xsl:value-of select="department" />
			</fo:block>
		</xsl:for-each>
	</fo:flow>
</fo:page-sequence>

<fo:page-sequence master-reference="report">
	<fo:flow flow-name="xsl-region-body">
		<fo:block text-align="center" font-size="18px" 
		font-weight="bold" margin-bottom="30px">
			List of exchanges:
		</fo:block>
			<fo:table border-bottom="1px solid #000000">
				
				<fo:table-column column-width="120px"/>
				<fo:table-column column-width="130px"/>
				<fo:table-column column-width="120px"/>
				<fo:table-column column-width="130px"/>
			
				<fo:table-header>
				    <fo:table-row>
				    	<fo:table-cell 
				    	border-left="2px solid #000000" 
				    	border-right="2px solid #000000" 
 						border-bottom="2px solid #000000" 
 						border-top="2px solid #000000"
 						padding="4px" >
				    		<fo:block font-weight="bold">Input Value</fo:block>
				     	</fo:table-cell>
				     	<fo:table-cell
				    	border-right="2px solid #000000" 
 						border-bottom="2px solid #000000" 
 						border-top="2px solid #000000" 
 						padding="4px" >
				       		<fo:block font-weight="bold">Input Currency</fo:block>
				     	</fo:table-cell>
				     	<fo:table-cell
				    	border-right="2px solid #000000" 
 						border-bottom="2px solid #000000" 
 						border-top="2px solid #000000" 
 						padding="4px" >
				       		<fo:block font-weight="bold">Output Value</fo:block>
				     	</fo:table-cell>
				     	<fo:table-cell
				    	border-right="2px solid #000000" 
 						border-bottom="2px solid #000000" 
 						border-top="2px solid #000000" 
 						padding="4px" >
				       		<fo:block font-weight="bold">Output Currency</fo:block>
				     	</fo:table-cell>
				    </fo:table-row>
			 	</fo:table-header>
			
			 <fo:table-body>
			 <xsl:for-each select="exchanges/exchange">
			   <fo:table-row>
			     <fo:table-cell
				    	border-left="2px solid #000000" 
				    	border-right="1px solid #000000" 
 						border-bottom="1px solid #000000"
 						padding="4px" >
			       <fo:block>
						<xsl:value-of select="input_value" />
			       </fo:block>
			     </fo:table-cell>
			     <fo:table-cell
				    	border-right="1px solid #000000" 
 						border-bottom="1px solid #000000"
 						padding="4px" >
			       <fo:block>
						<xsl:value-of select="input_currency" />
			       </fo:block>
			     </fo:table-cell>
			     <fo:table-cell
				    	border-right="1px solid #000000" 
 						border-bottom="1px solid #000000"
 						padding="4px" >
			       <fo:block>
						<xsl:value-of select="output_value" />
			       </fo:block>
			     </fo:table-cell>
			     <fo:table-cell
				    	border-right="2px solid #000000" 
 						border-bottom="1px solid #000000"
 						padding="4px" >
			       <fo:block>
						<xsl:value-of select="output_currency" />
			       </fo:block>
			     </fo:table-cell>
			   </fo:table-row>
			  </xsl:for-each>
			 </fo:table-body>			
		</fo:table>
	</fo:flow>
</fo:page-sequence>

<fo:page-sequence master-reference="stats">
	<fo:flow flow-name="xsl-region-body">
		<fo:block text-align="center" font-size="18px" 
		font-weight="bold" margin-bottom="20px">
			Statistics:
		</fo:block>
		<fo:block text-align="left" font-size="16px" 
		font-weight="bold" margin-bottom="15px" margin-top="30px" margin-left="30px">
			Total number of performed exchanges:
		</fo:block>
		<fo:block>
			<xsl:value-of select="count(//exchange)" />
		</fo:block>
		
		<fo:block text-align="left" font-size="16px" 
		font-weight="bold" margin-bottom="15px" margin-top="30px" margin-left="30px">
			Input Currency in percentages:
		</fo:block>
		<xsl:for-each select="exchanges//input_currency[generate-id() = generate-id(key('inputCurrencyID',.)[1])]">
        	<xsl:sort select="count(key('inputCurrencyID',.))" order="descending"/>
				<fo:block>
			       <xsl:value-of select="." /> - <xsl:value-of select="round((count(key('inputCurrencyID',.))  div (count(//exchange)) * 100))" />
			    </fo:block>
		</xsl:for-each>

		<fo:block text-align="left" font-size="16px" 
		font-weight="bold" margin-bottom="15px" margin-top="30px" margin-left="30px">
			Output Currency in percentages:
		</fo:block>
		<xsl:for-each select="exchanges//output_currency[generate-id() = generate-id(key('outputCurrencyID',.)[1])]">
        	<xsl:sort select="count(key('outputCurrencyID',.))" order="descending"/>
				<fo:block>
			       <xsl:value-of select="." /> - <xsl:value-of select="round((count(key('outputCurrencyID',.))  div (count(//exchange)) * 100))" />
			    </fo:block>
		</xsl:for-each>
	</fo:flow>
</fo:page-sequence>

</fo:root>
</xsl:template>
</xsl:stylesheet>